package com.example.eschool.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;

import com.example.eschool.R;
import com.example.eschool.activity.ErweimaActivity;
import com.example.eschool.activity.KczActivity;
import com.example.eschool.activity.KgsActivity;
import com.example.eschool.activity.KjgActivity;
import com.example.eschool.activity.KjycxActivity;
import com.example.eschool.activity.KyeActivity;
import com.example.eschool.activity.XwggActivity;
import com.example.eschool.activity.XyjsActivity;

public class HomeFragment extends Fragment {
    private static final int REQUEST_CODE_ERWEIMA = 1;
    private static final int REQUEST_CODE_KYE = 2;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        setClickListener(view.findViewById(R.id.tv_erweima), ErweimaActivity.class);
        setClickListener(view.findViewById(R.id.tv_kcz), KczActivity.class);
        setClickListener(view.findViewById(R.id.tv_kye), KyeActivity.class);
        setClickListener(view.findViewById(R.id.tv_xwgg), XwggActivity.class);
        setClickListener(view.findViewById(R.id.tv_xyjs), XyjsActivity.class);
        setClickListener(view.findViewById(R.id.tv_kgs), KgsActivity.class);
        setClickListener(view.findViewById(R.id.tv_kjg), KjgActivity.class);
        setClickListener(view.findViewById(R.id.tv_kjycx), KjycxActivity.class);
        return view;
    }

    private void setClickListener(View view, final Class<?> targetActivity) {
        if (view != null) {
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(getActivity(), targetActivity);
                    startActivityForResult(intent, REQUEST_CODE_ERWEIMA); // 使用 REQUEST_CODE_ERWEIMA 作为请求码
                }
            });
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_ERWEIMA) {

            if (resultCode == Activity.RESULT_OK) {
                // 返回成功的逻辑处理
            } else {
                // 返回失败的逻辑处理
            }
        }

    }
}
